package com.gnerv.rabbitmq.agent.command;

import com.gnerv.rabbitmq.agent.constants.ClusterNodeType;
import com.gnerv.rabbitmq.agent.constants.LogLevel;
import com.gnerv.rabbitmq.agent.model.entity.Node;
import com.gnerv.rabbitmq.agent.tools.ExecTools;
import com.google.common.collect.Lists;

import java.util.List;

/**
 * @author Gnerv LiGen
 */
public class ClusterCommand extends AbstractRabbitmqctlCommand {

    private ClusterCommand(Node node) {
        super();
        setNode(node);
    }

    public static ClusterCommand build(Node node) {
        return new ClusterCommand(node);
    }

    public ExecTools.ExecResult changeClusterNodeType(ClusterNodeType clusterNodeType) {
        List<String> changeClusterNodeType = Lists.newArrayList();
        changeClusterNodeType.add("change_cluster_node_type");
        changeClusterNodeType.add(clusterNodeType.getType());
        return run(changeClusterNodeType);
    }

    public ExecTools.ExecResult clusterStatus() {
        List<String> clusterStatus = Lists.newArrayList();
        clusterStatus.add("cluster_status");
        return run(clusterStatus);
    }

    public ExecTools.ExecResult joinCluster(String nodeName) {
        List<String> joinCluster = Lists.newArrayList();
        joinCluster.add("join_cluster");
        joinCluster.add(nodeName);
        return run(joinCluster);
    }

    public ExecTools.ExecResult forgetClusterNode(String nodeName) {
        List<String> joinCluster = Lists.newArrayList();
        joinCluster.add("forget_cluster_node");
        joinCluster.add(nodeName);
        return run(joinCluster);
    }

    public ExecTools.ExecResult renameClusterNode(String clusterName) {
        List<String> joinCluster = Lists.newArrayList();
        joinCluster.add("rename_cluster_node");
        joinCluster.add(clusterName);
        return run(joinCluster);
    }

    public ExecTools.ExecResult setDiskFreeLimit(String limit) {
        List<String> joinCluster = Lists.newArrayList();
        joinCluster.add("set_disk_free_limit");
        joinCluster.add(limit);
        return run(joinCluster);
    }

    public ExecTools.ExecResult setDiskFreeLimitMemRelative(String limit) {
        List<String> joinCluster = Lists.newArrayList();
        joinCluster.add("set_disk_free_limitmem_relative");
        joinCluster.add(limit);
        return run(joinCluster);
    }

    public ExecTools.ExecResult setVmMemoryHighWatermark(String limit) {
        List<String> joinCluster = Lists.newArrayList();
        joinCluster.add("set_vm_memory_high_watermark");
        joinCluster.add(limit);
        return run(joinCluster);
    }

    public ExecTools.ExecResult setLogLevel(LogLevel logLevel) {
        List<String> joinCluster = Lists.newArrayList();
        joinCluster.add("set_log_level");
        joinCluster.add(logLevel.getLevel());
        return run(joinCluster);
    }


}
